package com.miniso.robot.controller;

import com.miniso.robot.MessageUtil;
import com.miniso.robot.bean.*;
import com.miniso.robot.feign.RobotFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author guojunwang
 * @date 2021-10-18 16:47
 */
@RequestMapping("/send")
@RestController
public class SendMessageController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private RobotFeign robotFeign;



    @GetMapping()
    public void send(MultipartFile file) throws IOException {
//        TextMessage message = new TextMessage();
//        message.setContent("你好，世界！");
//        message.addMentionedMobile("13246089754");

//        ImageMessage message = new ImageMessage();
//        message.writeImage(file.getInputStream());

//        NewsMessage message = new NewsMessage();
//        message.addArticles(new NewsMessage.Article("测试","测试描述,测试描述,测试描述,测试描述,测试描述,测试描述","www.baidu.com","https://bkimg.cdn.bcebos.com/pic/d50735fae6cd7b899e5112b1a16b55a7d933c895a0f8?x-bce-process=image/resize,m_lfit,w_536,limit_1/format,f_jpg"));


        String test = robotFeign.uploadFile("1eef8f62-2856-423a-8f48-98fad860f1a6",file);

        FileMessage message = new FileMessage();
        message.setFile(test);

        robotFeign.sendMessage("1eef8f62-2856-423a-8f48-98fad860f1a6",message);
//        MessageUtil.sendMessage("1eef8f62-2856-423a-8f48-98fad860f1a6",message);
    }



    @GetMapping("card")
    public void send2() throws IOException {

        NewsCardMessage newsCardMessage = new NewsCardMessage();
        newsCardMessage.setSource("https://www.miniso.cn/Content/Make/images/logo.png","MINISO");
        newsCardMessage.setMainTitle("测试标题","这是一个测试消息，请勿回复。");
        newsCardMessage.setCardImage("https://miniso-application-1256969687.cos.ap-guangzhou.myqcloud.com/multi-compute/dev/20210922181140893/UPluspng.png",1.3);

        newsCardMessage.addSubTitle("二级标题","这是一个二级标题的描述");

        newsCardMessage.addHorizontalRedirect("miniso官网","点击miniso去官网","https://www.miniso.cn");
        newsCardMessage.addHorizontalRedirect("百度官网","点击去百度官网","https://www.baidu.com");
        newsCardMessage.addUrlJump("miniso官网","https://www.miniso.cn");
        newsCardMessage.addUrlJump("百度官网","https://www.baidu.com");

        newsCardMessage.setUrlJumpCardAction("https://www.miniso.cn");

        robotFeign.sendMessage("1eef8f62-2856-423a-8f48-98fad860f1a6",newsCardMessage);


    }


}
